-//
-// FlatBezelObjectCell.swift
-// Flat Bezel
-//
-// Created by Ruben Beltran del Rio on 2/8/23.
-// Copyright © 2023 BRNBW. All rights reserved.
-//
/*
import Foundation
-import Cocoa
class FlatBezelObjectCell: QSObjectCell {
- let preferredImagePosition: NSControl.ImagePosition = .imageAbove
+ override func preferredImagePosition() -> NSControl.ImagePosition {
+ return .imageAbove
+ }
- override func draw(withFrame cellFrame: NSRect, in controlView: NSView!) {
- let isFirstResponder = controlView.window?.firstResponder == controlView && !controlView.isKind(of: NSTableView.self)
-
- let dropTarget = self.isHighlighted && self.highlightsBy.contains(NSCell.StyleMask.changeBackgroundCellMask) && !self.isBezeled
-
- var fillColor: NSColor = self.backgroundColor ?? .textBackgroundColor
- if (isFirstResponder) {
- fillColor = self.highlightColor()
- }
- if (dropTarget) {
- fillColor = NSColor(red: 0.77, green: 0.91, blue: 0.96, alpha: 1)
+ override func draw(withFrame cellFrame: NSRect, in controlView: NSView?) {
+ if let controlView {
+
+ let isFirstResponder = controlView.window?.firstResponder == controlView && !(controlView is NSTableView)
+ let dropTarget = isHighlighted && ((highlightsBy.rawValue & NSCell.StyleMask.changeBackgroundCellMask.rawValue) != 0) && !isBezeled
+
+ var fillColor: NSColor?
+ let strokeColor = NSColor.clear
+
+ if isFirstResponder {
+ fillColor = self.highlightColor()
+ } else {
+ fillColor = self.backgroundColor
+ }
+
+ if dropTarget {
+ fillColor = NSColor(red: 0.77, green: 0.91, blue: 0.96, alpha: 1)
+ }
+
+ fillColor?.setFill()
+ strokeColor.setStroke()
+
+ let roundRect = NSBezierPath()
+ roundRect.append(withRoundedRectangle: cellFrame, withRadius: cellRadiusFactor())
+ roundRect.fill()
+
+ drawInterior(withFrame: drawingRect(forBounds: cellFrame), in: controlView)
}
-
- var strokeColor: NSColor = .clear
-
- fillColor.setFill()
- strokeColor.setStroke()
-
- let roundRect = NSBezierPath()
- roundRect.appendRoundedRect(cellFrame, xRadius: cellRadiusFactor(), yRadius: cellRadiusFactor())
- roundRect.fill()
-
- self.drawInterior(withFrame: self.drawingRect(forBounds: cellFrame), in: controlView)
}
- override func titleRect(forBounds rect: NSRect) -> NSRect {
- super.titleRect(forBounds: rect.offsetBy(dx: 0, dy: -4))
+ override func titleRect(forBounds _rect: NSRect) -> NSRect {
+ var rect = _rect
+ rect = NSOffsetRect(rect, 0, -4)
+ return super.titleRect(forBounds: rect)
}
override func drawText(for drawObject: QSObject!, withFrame cellFrame: NSRect, in controlView: NSView!) {
- if self.imagePosition == .imageOnly {
- return;
+ if imagePosition == .imageOnly {
+ return
}
var abbrString: String? = nil
+
if controlView.responds(to: #selector(QSSearchObjectView.matchedString)) {
abbrString = (controlView as! QSSearchObjectView).matchedString()
}
- var nameString: String? = drawObject.displayName()
- var hitMask: AutoreleasingUnsafeMutablePointer<NSIndexSet?>? = nil
+ var nameString: String? = nil
+ var hitMask: NSIndexSet? = nil
- var ranker = drawObject.ranker()
- if let ranker, let abbrString {
- nameString = ranker.matchedString(forAbbreviation: abbrString, hitmask: hitMask, inContext: nil)
+ let ranker = drawObject.ranker()
+ if ranker != nil && abbrString != nil {
+ nameString = ranker?.matchedString(forAbbreviation: abbrString, hitmask: &hitMask, inContext: nil)
}
- var rankedStringIsName = nameString == drawObject.displayName()
- if nameString == nil {
- nameString = drawObject.identifier() ?? "Unknown"
+ if (nameString == nil) {
+ nameString = drawObject.displayName()
}
- var useAlternateColor = false
- if let controlView = controlView as? NSTableView {
- useAlternateColor = controlView.isRowSelected(controlView.row(at: cellFrame.origin))
- }
+ let rankedStringIsName = nameString == drawObject.displayName() || nameString == nil
- var mainColor: NSColor? = textColor()
- if mainColor == nil {
- mainColor = useAlternateColor ? .alternateSelectedControlTextColor : .controlTextColor
+ if nameString == nil {
+ nameString = drawObject.identifier() ?? "Unknown"
}
- var fadedColor = mainColor!.withAlphaComponent(0.50)
- var textDrawRect = titleRect(forBounds: cellFrame)
+ let useAlternateColor = controlView is NSTableView && (controlView as! NSTableView).isRowSelected((controlView as! NSTableView).row(at: cellFrame.origin))
+ let mainColor = textColor() ?? (useAlternateColor ? .alternateSelectedControlTextColor : .controlTextColor)
+ let fadedColor = mainColor.withAlphaComponent(0.50)
+ let textDrawRect = titleRect(forBounds: cellFrame)
+
- var titleString = NSMutableAttributedString(string: nameString!)
- titleString.setAttributes(rankedStringIsName ? nameAttributes : detailAttributes, range: NSMakeRange(0, titleString.length))
+ let titleString = NSMutableAttributedString(string: nameString!)
+ let nameAttributes = (value(forKey: "nameAttributes") as? [NSAttributedString.Key : Any])
+ let detailsAttributes = (value(forKey: "detailsAttributes") as? [NSAttributedString.Key : Any])
+ titleString.setAttributes(rankedStringIsName ? nameAttributes : detailsAttributes, range: NSMakeRange(0, titleString.length))
if abbrString != nil && abbrString!.hasPrefix("QSActionMnemonic") {
titleString.addAttribute(.foregroundColor, value: rankedStringIsName ? fadedColor : fadedColor.withAlphaComponent(0.8), range: NSMakeRange(0, titleString.length))
- } else {
- var i = 0
- var j = 0
- var hits: [Int] = []
- count = hitMask?.
+
+ var hits: Int = 0
+ let count = hitMask?.getIndexes(&hits, maxCount: titleString.length, inIndexRange: nil)
+ for i in 0..<(count ?? 0) {
+ for j in 1.. {
+ }
+ }
}
- }
}
-
NSUInteger i = 0;
NSUInteger j = 0;
NSUInteger hits[[titleString length]];
[titleString drawInRect:centerRectInRect(centerRect, textDrawRect)];
}
+- (void)drawSearchPlaceholderWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
+ NSString *defaultText = NSLocalizedStringWithDefaultValue(@"Type to search", nil, [NSBundle mainBundle], @"Type to search", @"Hint that appears in the first pane of the QS interface when it's empty.");
+ NSSize textSize = [defaultText sizeWithAttributes:nameAttributes];
+ NSRect textRect = centerRectInRect(rectFromSize(textSize), cellFrame);
+ BOOL isFirstResponder = [[controlView window] firstResponder] == controlView && ![controlView isKindOfClass:[NSTableView class]];
+
+ if (isFirstResponder && [controlView isKindOfClass:[QSSearchObjectView class]]) {
+ NSImage *find = [NSImage imageWithSystemSymbolName:@"magnifyingglass.circle.fill" accessibilityDescription:nil];
+
+
+ [find setSize:QSSize16];
+ NSRect findImageRect = expelRectFromRectOnEdge(centerRectInRect(rectFromSize([find size]), cellFrame), textRect, NSRectEdgeMinX, -2);
+
+
+ NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
+ [graphicsContext saveGraphicsState];
+ CGContextRef context = [graphicsContext CGContext];
+ CGContextBeginTransparencyLayerWithRect(context, findImageRect, nil);
+ CGContextSetBlendMode(context, kCGBlendModeNormal);
+ [find drawInRect:findImageRect fromRect:rectFromSize([find size]) operation:NSCompositingOperationSourceOver fraction:1];
+ CGContextSetBlendMode(context, kCGBlendModeSourceIn);
+ CGContextSetFillColorWithColor(context, [[NSColor textColor] CGColor]);
+ CGContextFillRect(context, findImageRect);
+ CGContextEndTransparencyLayer(context);
+
+ [defaultText drawInRect:textRect withAttributes:nameAttributes];
+ }
+}
+
@end
*/